/*
  Blalarm
  Created by Elliot Coad
  2010-02-18 
 */
int sensorPin = 2;
int motorPin = 6;
int sensorValue = 0;

boolean allowAlarm = true;

void setup() {
  Serial.begin(9600);
  pinMode(motorPin, OUTPUT);
}

void loop() {  
  if (allowAlarm) {
    //Get average sensor values
    int i = 0;
    int sensorValues;
    
    while (i < 10) {
      sensorValue += analogRead(sensorPin); 
      delay(10);   
      i++;
    } 
    
    Serial.println(sensorValue);

    //Alarm is heard
    if (sensorValue > 500) {
      openBlinds();
    }

    sensorValue = 0;
    delay(100);      
  } else {
    delay(30000);
  }       
}

void openBlinds() {
  Serial.println("Open Blinds!");
  allowAlarm = false;
  
  digitalWrite(motorPin, HIGH);
  delay(8000);
  digitalWrite(motorPin, LOW);
}